var kolom ={};
var kolomkaku={};
var tabel = "#grid_"+mod;

switch(mod){
	case "penduduk":
		
    	kolom[mod]=[
			{field:'ck', checkbox:true},
            {field:'tahun',title:'Tahun',width:150},
            {field:'jml_penduduk',title:'Jml. Penduduk',width:250,align:'right'},
            {field:'jumlah_pencari_kerja',title:'Jml. Pencari Kerja',width:200,align:'right'},
           
            
        ];
        
        judul="Data Kependudukan";
	break;
	case "headline":
		
    	kolom[mod]=[
			{field:'ck', checkbox:true},
            {field:'judul',title:'Judul',width:150},
            {field:'isi',title:'Isi Headline',width:550,align:'left'},
           
        ];
        
        judul="Data Headline";
	break;
	case "potensi":
		
    	kolom[mod]=[
			{field:'ck', checkbox:true},
            {field:'komoditi',title:'Komoditi',width:450},
            {field:'tahun',title:'Tahun',width:100,align:'center'},
			{field:'jumlah',title:'Jumlah',width:100,align:'right'},
			{field:'satuan',title:'Satuan',width:100,align:'center'},
           
        ];
        
        judul="Data Potensi";
	break;
	case "pdrb":
		
    	kolom[mod]=[
			{field:'ck', checkbox:true},
            
            {field:'tahun',title:'Tahun',width:100,align:'center'},
			{field:'pmdn',title:'PMDN',width:100,align:'right'},
			{field:'satuan_pmdn',title:'Satuan',width:100,align:'center'},
			{field:'pma',title:'PMA',width:100,align:'right'},
			{field:'satuan_pma',title:'Satuan',width:100,align:'center'},
			{field:'pdrb',title:'PDRB',width:100,align:'right'},
			{field:'satuan_pdrb',title:'Satuan',width:100,align:'center'},
           
        ];
        
        judul="Data PDRB";
	break;
	case "ekonomi":
		
    	kolom[mod]=[
			{field:'ck', checkbox:true},
            
            {field:'tahun',title:'Tahun',width:100,align:'center'},
			{field:'pdrb',title:'PDRB',width:100,align:'right'},
			{field:'satuan_pdrb',title:'Satuan',width:100,align:'center'},
			{field:'pendatan_kapita',title:'Pendapatan PerKapita',width:150,align:'right'},
			{field:'satuan_pendapatan',title:'Satuan',width:100,align:'center'},
			{field:'inflasi',title:'Inflasi (%)',width:100,align:'right'},
		
           
        ];
        
        judul="Data Pertumbuhan Ekonomi";
	break;
}

$(tabel).datagrid({
    title:judul,
    height:frmHeight-200,
    width:frmWidth-300,
	iconCls: 'table',
	rownumbers:true,
   // fit:true,
    striped:true,
    pagination:true,
    sortable:true,
    url:host+"adminpanel/get_data/"+mod,
   // fit:true,		
	nowrap: false,
    singleSelect:true,
    frozenColumns:[
			 kolomkaku[mod]         
		],		
    columns:[
            kolom[mod]
        ],
	
	toolbar:[
				{
					text:'Tambah',
					iconCls:'add',
					handler:function(){
						cek_grid('add');
					},
					disabled:(mod=='headline' ? true : false)
				},'-',
				{
					text:'Edit',
					iconCls:'edit',
					handler:function(){
						cek_grid('edit');
					}
				},'-',
				{
					text:'Hapus',
					iconCls:'remove',
					handler:function(){
						cek_grid('delete');
					}
				}
				
			],	
});


function cek_grid(tbl){
	var w,h,t;
	var row = $(tabel).datagrid('getSelected');
	switch(mod){
		case "penduduk":
			w=frmWidth-800;
			h=frmHeight-280;
			t="Form Data Kependudukan";
		break;
		case "headline":
			w=frmWidth-600;
			h=frmHeight-150;
			t="Form Data Headline";
		break;
		case "potensi":
			
			t="Form Data Potensi";
		break;
		case "pdrb":
			w=frmWidth-800;
			h=frmHeight-150;
			t="Form Data PDRB";
		break;
		case "ekonomi":
			w=frmWidth-800;
			h=frmHeight-150;
			t="Form Data Pertumbuhan Ekonomi";
		break;
	}
	
	
		if(tbl!='add'){
			if(row){
				if(tbl=='delete'){
					$.messager.confirm('Confirm','Yakin Data Ini Akan Dihapus ?',function(r){  
						if (r==true){  
							$.post(host+'adminpanel/hapus/'+mod,{id:row.id,},function(resp){
								if(resp==1){$.messager.alert("Data","Data Sudah Terhapus",'info');$(tabel).datagrid('reload');}		   
							});	
						}  
					}); 
				}
				
				else{
					$.post(host+'adminpanel/get_formna/'+mod,{sts:'edit',id:row.id},function(r){
						window_na(r,t,w,h);
						tinyMCE.init({
							selector : "textarea",
							plugins : "pagebreak,table,code,save,insertdatetime,preview,media,searchreplace,contextmenu,paste,directionality,image",		
				 
						});	
					});
					
				}
			
				
			}
			else{$.messager.alert("Data","Pilih Salah Satu Data",'error');} 
		}
		else{
			$.post(host+'adminpanel/get_formna/'+mod,{sts:'add'},function(r){
				window_na(r,t,w,h);
			});
			
		}
}	